﻿using WF_AppFuel.Validation.Attributes;
using WF_AppFuel.Validation.Base;

namespace WF_AppFuel.Validation.Engines
{
    /// <summary>
    /// This engine is used for validating fields which values should be text only.
    /// </summary>
    /// <author>Arjay C. Nacion</author>
    public sealed class IsAlphaValidationEngine : BaseValidationEngine
    {
        public override bool Run()
        {
            IsAlpha attrib = (IsAlpha)ValidationAttribute;
            bool allowWhiteSpace = attrib.IsWhiteSpaceAllowed;

            if (Value == null)
                return false;

            foreach (char c in Value.ToString())
            {
                if (allowWhiteSpace && char.IsWhiteSpace(c))
                    continue;

                if (!char.IsLetter(c))
                    return false;
            }

            return true;
        }
    }
}
